#include "nosal/log/logging.h"
#include "nosal/log/logger.h"
#include "gtest/gtest.h"

using namespace ::testing;
using namespace netaos::nosal::log;

namespace
{
constexpr char appId[]{"APP"};
constexpr char appDescr[]{"Test application with slog2 logging"};
}  // namespace

struct LoggingTest: Test
{
    const LogLevel loglevel{LogLevel::kVerbose};
    const LogMode logmode{LogMode::kConsole};
};

TEST_F(LoggingTest, shouldInitializeOnlyOnce)
{
    {
        InitLogging(appId, appDescr, loglevel, logmode);
    }
    InitLogging(appId, appDescr, loglevel, logmode);
    InitLogging("RPT", "Other attempt with new appId", LogLevel::kInfo, LogMode::kFile);
}

TEST_F(LoggingTest, loggerShouldBeCreatedWithWarnLogLevelByDefault)
{
    constexpr char ctxId[]{"CTX0"};
    constexpr auto expectedLogLevel{LogLevel::kWarn};

    auto& logger = CreateLogger(ctxId, "Test context", expectedLogLevel);

    EXPECT_FALSE(logger.IsEnabled(LogLevel::kVerbose));
    EXPECT_FALSE(logger.IsEnabled(LogLevel::kDebug));
    EXPECT_FALSE(logger.IsEnabled(LogLevel::kInfo));
    EXPECT_TRUE(logger.IsEnabled(LogLevel::kWarn));
    EXPECT_TRUE(logger.IsEnabled(LogLevel::kError));
    EXPECT_TRUE(logger.IsEnabled(LogLevel::kFatal));
}


TEST_F(LoggingTest, shouldCreateIndependentLoggers)
{
    constexpr char ctxId[]{"CTX1"};
    constexpr char otherCtxId[]{"CTX2"};

    constexpr char ctxDescr[]{"Test context"};
    constexpr char otherCtxDescr[]{"Other test context"};

    constexpr auto ctxLogLevel{LogLevel::kInfo};
    constexpr auto otherCtxLogLevel{LogLevel::kError};

    auto& logger = CreateLogger(ctxId, ctxDescr, ctxLogLevel);
    auto& otherLogger = CreateLogger(otherCtxId, otherCtxDescr, otherCtxLogLevel);

    EXPECT_NE(&logger, &otherLogger);
}
